package cn.itcast.c_one2one;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.junit.Test;

public class App {

	private static SessionFactory sf;
	static {
		Configuration cf = new Configuration();
		cf.configure();
		cf.addClass(IdCard.class);
		cf.addClass(User.class);
		sf = cf.buildSessionFactory();
	}
	
	@Test
	public void getSave(){
		Session session = sf.openSession();
		session.beginTransaction();
		
		// 用户
		User user = new User();
		user.setUserName("jack");
		// 身份证
		IdCard idCard = new IdCard();
		idCard.setCardNum("4412021515");
		idCard.setPlace("广州XXX");
		// 关系
		idCard.setUser(user);
		// ----保存----
		session.save(idCard);
		
		session.getTransaction().commit();
		session.close();
	}
}
